package com.gusti.turnos.dao.impl;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.gusti.turnos.dao.IEventDao;
import com.gusti.turnos.model.AppointmentEvent;
import com.gusti.turnos.model.BirthdayEvent;
import com.gusti.turnos.model.Event;
import com.gusti.turnos.util.Debug;

/**
 * 
 * @author gusti
 *
 */
@Repository
public class EventDao extends ProjectDao<Event> implements IEventDao {

	//AppointmentEvents
	@SuppressWarnings("unchecked")
	@Override
	public List<AppointmentEvent> retrieveAppointmentEvents() {

		List<AppointmentEvent> events = new ArrayList<AppointmentEvent>();
		Query query = null;
		try {
			query = em.createQuery( "FROM AppointmentEvent" );
			events = (List<AppointmentEvent>)query.getResultList();
		} catch ( Exception e ) {
			Debug.error( e );
		}

		return events;
	}

	//BirthdayEvents
	@SuppressWarnings("unchecked")
	@Override
	public List<BirthdayEvent> retrieveBirthdayEvents() {

		List<BirthdayEvent> events = new ArrayList<BirthdayEvent>();
		Query query = null;
		try {
			query = em.createQuery( "FROM BirthdayEvent" );
			events = (List<BirthdayEvent>)query.getResultList();
		} catch ( Exception e ) {
			Debug.error( e );
		}

		return events;
	}
}
